<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>花间村 - 管理面板</title>
    <link rel="stylesheet" href="{{ asset('css/wechat_service_account.css') }}">
    <style>
        .container {
            padding: 15px;
        }

        .header {
            background: #fff;
            padding: 20px;
            border-radius: 12px;
            margin-bottom: 20px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        .header h2 {
            margin: 0;
            color: #333;
            font-size: 20px;
        }

        .identity-switch {
            margin-top: 10px;
            padding: 10px 20px;
            background: #07C160;
            color: white;
            border: none;
            border-radius: 20px;
            font-size: 14px;
            cursor: pointer;
        }

        /* 添加库存管理按钮样式 */
        .inventory-btn {
            margin-top: 15px;
            padding: 12px 20px;
            background: #1890ff;
            color: white;
            border: none;
            border-radius: 20px;
            font-size: 14px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
        }

        .inventory-btn:hover {
            background: #40a9ff;
        }

        .order-item {
            background: #fff;
            border-radius: 12px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        .order-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 10px;
            border-bottom: 1px solid #f0f0f0;
        }

        .order-id {
            font-size: 14px;
            color: #666;
        }

        .order-status {
            font-size: 14px;
            color: #07C160;
        }

        .order-content {
            padding: 10px 0;
        }

        .order-product {
            display: flex;
            padding: 10px 0;
            border-bottom: 1px solid #f0f0f0;
        }

        .product-info {
            flex: 1;
        }

        .product-name {
            font-size: 15px;
            color: #333;
            margin-bottom: 5px;
        }

        .product-price,
        .product-quantity {
            font-size: 13px;
            color: #666;
        }

        .order-footer {
            padding-top: 10px;
            text-align: right;
            font-size: 14px;
            color: #333;
        }

        .total-price {
            font-weight: 500;
            color: #e53e3e;
        }

        .pagination {
            text-align: center;
            margin-top: 20px;
            padding-bottom: 30px;
        }

        .pagination a {
            display: inline-block;
            padding: 8px 12px;
            margin: 0 5px;
            background: #fff;
            border: 1px solid #ddd;
            border-radius: 4px;
            text-decoration: none;
            color: #333;
        }

        .pagination a.active {
            background: #07C160;
            color: white;
            border-color: #07C160;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">
            <h2>后台管理面板</h2>
            <!-- 添加商品库存管理按钮 -->
            <a href="{{ route('wechat.service.account.inventory') }}" class="inventory-btn">商品库存管理</a>
            <form method="GET" action="{{ route('wechat.service.account.my') }}">
                <button type="submit" class="identity-switch">切换到前台用户</button>
            </form>
        </div>

        <h3 style="margin-bottom: 15px; color: #333;">所有订单列表</h3>

        @if($orders->count() > 0)
        @foreach($orders as $order)
        <div class="order-item">
            <div class="order-header">
                <div class="order-id">订单号: {{ $order->order_number }}</div>
                <div class="order-status">{{ $order->status }}</div>
            </div>
            <div class="order-content">
                <!-- @foreach($order->items as $item)
                            <div class="order-product">
                                <div class="product-info">
                                    <div class="product-name">{{ $item->product_name }}</div>
                                    <div class="product-price">¥{{ $item->price }} × {{ $item->quantity }}</div>
                                </div>
                            </div>
                        @endforeach -->
            </div>
            <div class="order-footer">
                总价: <span class="total-price">¥{{ $order->total_price }}</span>
                <a href="{{ route('wechat.service.account.orders.show', $order->id) }}" style="margin-left: 15px; color: #07C160; text-decoration: none;">查看详情</a>
            </div>
        </div>
        @endforeach

        @else
        <div style="background: #fff; padding: 30px; border-radius: 12px; text-align: center; color: #666;">
            暂无订单数据
        </div>
        @endif

        <!-- 移动端友好的分页显示 -->
        @if($orders->hasPages())
        <div class="d-flex justify-content-center mt-4">
            <nav aria-label="订单分页导航">
                <ul class="pagination pagination-sm mb-0" style="flex-wrap: wrap; justify-content: center;">
                    {{-- 上一页 --}}
                    @if($orders->onFirstPage())
                        <li class="page-item disabled">
                            <span class="page-link" style="font-size: 14px; padding: 10px 12px;">&laquo;</span>
                        </li>
                    @else
                        <li class="page-item">
                            <a class="page-link" href="{{ $orders->previousPageUrl() }}" rel="prev" style="font-size: 14px; padding: 10px 12px;">&laquo;</a>
                        </li>
                    @endif

                    {{-- 分页数字 --}}
                    @php
                        $current = $orders->currentPage();
                        $last = $orders->lastPage();
                        // 在移动端只显示当前页和前后各1页
                        $start = max(1, $current - 1);
                        $end = min($start + 2, $last);
                        $start = max(1, $end - 2);
                    @endphp

                    @if($start > 1)
                        <li class="page-item">
                            <a class="page-link" href="{{ $orders->url(1) }}" style="font-size: 14px; padding: 10px 12px;">1</a>
                        </li>
                        @if($start > 2)
                            <li class="page-item disabled d-none d-sm-block">
                                <span class="page-link" style="font-size: 14px; padding: 10px 12px;">...</span>
                            </li>
                        @endif
                    @endif

                    @for($i = $start; $i <= $end; $i++)
                        @if($i == $current)
                            <li class="page-item active" aria-current="page">
                                <span class="page-link" style="font-size: 14px; padding: 10px 12px;">{{ $i }}</span>
                            </li>
                        @else
                            <li class="page-item">
                                <a class="page-link" href="{{ $orders->url($i) }}" style="font-size: 14px; padding: 10px 12px;">{{ $i }}</a>
                            </li>
                        @endif
                    @endfor

                    @if($end < $last)
                        @if($end < $last - 1)
                            <li class="page-item disabled d-none d-sm-block">
                                <span class="page-link" style="font-size: 14px; padding: 10px 12px;">...</span>
                            </li>
                        @endif
                        <li class="page-item">
                            <a class="page-link" href="{{ $orders->url($last) }}" style="font-size: 14px; padding: 10px 12px;">{{ $last }}</a>
                        </li>
                    @endif

                    {{-- 下一页 --}}
                    @if($orders->hasMorePages())
                        <li class="page-item">
                            <a class="page-link" href="{{ $orders->nextPageUrl() }}" rel="next" style="font-size: 14px; padding: 10px 12px;">&raquo;</a>
                        </li>
                    @else
                        <li class="page-item disabled">
                            <span class="page-link" style="font-size: 14px; padding: 10px 12px;">&raquo;</span>
                        </li>
                    @endif
                </ul>
            </nav>
        </div>
        
        <!-- 移动端额外显示当前页信息 -->
        <div class="text-center mt-2" style="font-size: 14px; color: #666;">
            第 {{ $current }} 页，共 {{ $last }} 页
        </div>
        @endif
    </div>
</body>

</html>